﻿@model IEnumerable<Data.Web.Category> 
@{
    var id = 0;
    if(ViewBag.id!=null){
        id = ViewBag.id;
    }

    var lst = Model.Where(e => e.Parent == id).ToList();
} 
<p>
    @Html.ActionLink("Thêm mới ", "Create")
</p>
<table class="table table-bordered">

    <tr>
        <th>ID
        </th>
        <th>Tiêu đề
        </th>
        <th>Danh mục cha</th>
        <th>Trạng thái
        </th>
        <th></th>
    </tr>

  @sub(lst,"",0)

</table>
@helper sub(IEnumerable<Data.Web.Category> lst,string parent, int lever){
    foreach (var item in lst)
    {
        <tr>
            <td> 
                @Html.DisplayFor(modelItem => item.ID)
            </td>
            <td>
               @for (int i = 0; i < lever; i++) {@Html.Raw("___  ") }  @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                <a href="/cate/index/@item.Parent">@parent</a>                                     
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Status)
            </td>
            <td>
                 @Html.ActionLink("Thêm", "Create", new { id = item.ID }) |
                @Html.ActionLink("Sửa", "Edit", new { id = item.ID })   
                @Html.ActionLink("Xóa", "Delete", new { id = item.ID })
            </td>
        </tr>
        var lst2 = Model.Where(e => e.Parent == item.ID).ToList();
        @sub(lst2,item.Name,lever+1)
    }
}